// 获取应用实例
const app = getApp();
const i18n = require('../../i18n/index');

Page({
  data: {
    l10n: {
      title: '',
      lastUpdated: '',
      accept: '',
      back: '',
      languageSettings: '',
      introTitle: '',
      introP1: '',
      introP2: '',
      collectTitle: '',
      personalTitle: '',
      personalP: '',
      personalL1: '',
      personalL2: '',
      personalL3: '',
      healthTitle: '',
      healthP: '',
      usageTitle: '',
      usageP: '',
      usageL1: '',
      usageL2: '',
      usageL3: '',
      usageL4: '',
      usageL5: '',
      shareTitle: '',
      shareP: '',
      shareL1: '',
      shareL2: '',
      shareL3: '',
      shareL4: '',
      securityTitle: '',
      securityP: '',
      rightsTitle: '',
      rightsP: '',
      rightsL1: '',
      rightsL2: '',
      rightsL3: '',
      rightsL4: '',
      rightsL5: '',
      childrenTitle: '',
      childrenP: '',
      changesTitle: '',
      changesP: '',
      contactTitle: '',
      contactP: '',
      emailLabel: '',
      addressLabel: '',
      phoneLabel: '',
      addressValue: ''
    }
  },

  onLoad: function() {
    console.log('隐私政策页面加载');
    this.updateTexts();
  },

  onShow: function() {
    console.log('隐私政策页面显示');
    this.updateTexts();
  },

  updateTexts: function() {
    const t = (k: string) => i18n.t(`privacyPage.${k}`);
    const l10n = {
      title: t('title'),
      lastUpdated: t('lastUpdated'),
      accept: t('accept'),
      back: t('back'),
      languageSettings: t('languageSettings'),
      introTitle: t('introTitle'),
      introP1: t('introP1'),
      introP2: t('introP2'),
      collectTitle: t('collectTitle'),
      personalTitle: t('personalTitle'),
      personalP: t('personalP'),
      personalL1: t('personalL1'),
      personalL2: t('personalL2'),
      personalL3: t('personalL3'),
      healthTitle: t('healthTitle'),
      healthP: t('healthP'),
      usageTitle: t('usageTitle'),
      usageP: t('usageP'),
      usageL1: t('usageL1'),
      usageL2: t('usageL2'),
      usageL3: t('usageL3'),
      usageL4: t('usageL4'),
      usageL5: t('usageL5'),
      shareTitle: t('shareTitle'),
      shareP: t('shareP'),
      shareL1: t('shareL1'),
      shareL2: t('shareL2'),
      shareL3: t('shareL3'),
      shareL4: t('shareL4'),
      securityTitle: t('securityTitle'),
      securityP: t('securityP'),
      rightsTitle: t('rightsTitle'),
      rightsP: t('rightsP'),
      rightsL1: t('rightsL1'),
      rightsL2: t('rightsL2'),
      rightsL3: t('rightsL3'),
      rightsL4: t('rightsL4'),
      rightsL5: t('rightsL5'),
      childrenTitle: t('childrenTitle'),
      childrenP: t('childrenP'),
      changesTitle: t('changesTitle'),
      changesP: t('changesP'),
      contactTitle: t('contactTitle'),
      contactP: t('contactP'),
      emailLabel: t('emailLabel'),
      addressLabel: t('addressLabel'),
      phoneLabel: t('phoneLabel'),
      addressValue: t('addressValue')
    };
    this.setData({ l10n });
    wx.setNavigationBarTitle({ title: l10n.title });
  },

  // 接受隐私政策
  acceptPrivacy: function() {
    wx.setStorageSync('privacyAccepted', true);
    wx.showToast({
      title: i18n.t('privacyPage.acceptedToast'),
      icon: 'success',
      duration: 1500
    });
    setTimeout(() => {
      this.goBack();
    }, 1500);
  },

  // 返回上一页
  goBack: function() {
    const pages = getCurrentPages();
    if (pages.length > 1) {
      wx.navigateBack({
        delta: 1
      });
    } else {
      wx.switchTab({
        url: '/pages/index/index'
      });
    }
  },

  // 跳转语言设置（如果未来需要）
  goLanguage: function() {
    wx.navigateTo({ url: '/pages/language/language' });
  }
})


